using System;
using SharedKernel.Domain;
using UserService.Domain.ValueObjects;

namespace UserService.Domain.Models
{
    /// <summary>
    /// 用户实体
    /// </summary>
    public class User : BaseId<long>
    { 
        /// <summary>
        /// Desc:用户账号
        /// Default:
        /// Nullable:False
        /// </summary>           
        public string Account { get; set; } = null!;

        /// <summary>
        /// Desc:账号密码
        /// Default:
        /// Nullable:False
        /// </summary>           
        public string Password { get; set; } = null!;

        /// <summary>
        /// Desc:校验码
        /// Default:
        /// Nullable:False
        /// </summary>           
        public string CheckCode { get; set; } = null!;

        /// <summary>
        /// Desc:用户姓名
        /// Default:
        /// Nullable:False
        /// </summary>           
        public string Name { get; set; } = null!;

        /// <summary>
        /// Desc:出生日期
        /// Default:
        /// Nullable:True
        /// </summary>           
        public DateTime? Birthday { get; set; }

        /// <summary>
        /// Desc:手机号
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string? Phone { get; set; }

        /// <summary>
        /// Desc:邮箱地址
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string? Email { get; set; }

        /// <summary>
        /// Desc:账号状态
        /// Default:
        /// Nullable:False
        /// </summary>           
        public int Status { get; set; }

        /// <summary>
        /// Desc:首次添加时间
        /// Default:
        /// Nullable:False
        /// </summary>           
        public DateTime FirstAddTime { get; set; }

        /// <summary>
        /// Desc:最后修改时间
        /// Default:
        /// Nullable:False
        /// </summary>           
        public DateTime LastModifyTime { get; set; }

        /// <summary>
        /// Desc:删除时间
        /// Default:
        /// Nullable:True
        /// </summary>           
        public DateTime? DeleteTime { get; set; }

        /// <summary>
        /// Desc:所属角色
        /// Default:
        /// Nullable:False
        /// </summary>           
        public long RoleId { get; set; }

        /// <summary>
        /// Desc:是否在线
        /// Default:true
        /// Nullable:False
        /// </summary>           
        public bool Online { get; set; }

        /// <summary>
        /// Desc:会员类型
        /// Default:1
        /// Nullable:False
        /// </summary>           
        public int MemberType { get; set; }

        /// <summary>
        /// Desc:允许接收短信
        /// Default:true
        /// Nullable:False
        /// </summary>           
        public bool ReceiveSMS { get; set; }

        /// <summary>
        /// Desc:头像图片
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string? HeadImage { get; set; }

        /// <summary>
        /// Desc:当前所在省码（省：成都，绵阳，重庆）
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string? CurrentCityCode { get; set; }

        /// <summary>
        /// Desc:当前所在省
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string? CurrentCity { get; set; }

        /// <summary>
        /// 当月免费短信条数
        /// </summary>           
        public int SmsCount { get; set; }

        /// <summary>
        /// 领取免费短信年月
        /// </summary>           
        public string? ReceiveFreeSmsMonth { get; set; }
        /// <summary>
        /// Desc:移动端最后更新日期
        /// Default:
        /// Nullable:True
        /// </summary>           
        public DateTime? AppLastModifyTime { get; set; }

        /// <summary>
        /// Desc:当前所在市码（市：武侯区，涪城区，南岸区）
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string? CurrentAdCode { get; set; }
        /// <summary>
        /// Desc:当前所在市码
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string? CurrentAd { get; set; }
        /// <summary>
        /// Desc:是否认证申请
        /// Default:true
        /// Nullable:False
        /// </summary>           
        public bool RequestAudit { get; set; }

        /// <summary>
        /// Desc:认证申请时间
        /// Default:
        /// Nullable:True
        /// </summary>           
        public DateTime? RequestAuditDate { get; set; }
        /// <summary>
        /// 累积获得积分 
        /// </summary>           
        public long Points { get; set; }
        /// <summary>
        /// 冻结积分 
        /// </summary>           
        public long FreezePoints { get; set; }
        /// <summary>
        /// 剩余可用积分 
        /// </summary>           
        public long CanUsePoints { get; set; }
        /// <summary>
        /// 是否是代理
        /// </summary>
        public bool IsAgent { get; set; }
        /// <summary>
        /// 余额
        /// </summary>
        public decimal Balance { get; set; } = 0;
        /// <summary>
        /// 下级订单累积返点金额
        /// </summary>
        public decimal InviteOrderBalance { get; set; } = 0;
        /// <summary>
        /// 邀请码
        /// </summary>
        public string? InviteCode { get; set; }

        /// <summary>
        /// 邀请人id
        /// </summary>
        public long InviteUserId { get; set; }
        /// <summary>
        /// 直属下级人数
        /// </summary>
        public int InviteCount { get; set; }


        /// <summary>
        /// 公共无参数构造函数，用于ORM框架
        /// </summary>
        public User() : base(0) { }

        /// <summary>
        /// 创建用户
        /// </summary>
        /// <param name="data"></param> 
        /// <returns>用户实体</returns>
        public static User Create(CreateUserValueObject data)
        {
            return new User();
        }

        /// <summary>
        /// 更新用户信息
        /// </summary>
        /// <param name="data"></param> 
        public void Update(UpdateUserValueObject data)
        { 

        }

        /// <summary>
        /// 更改密码
        /// </summary>
        /// <param name="newPasswordHash">新密码哈希</param>
        public void ChangePassword(string newPasswordHash)
        {
            if (string.IsNullOrWhiteSpace(newPasswordHash))
                throw new ArgumentNullException(nameof(newPasswordHash), "新密码哈希不能为空");

            Password = newPasswordHash;
        }
    }
}